Thanks to all who sent in their comments on my "mini-dissertation" of a few days ago. I am all straightened out on this now.
Shamim Mohamed said it this way in referring to my "beast in captivity" program snippet:
>In method 1, you are creating a new list and assigning a reference to it
>to the name x.
>In method 2, you are modifying the list that x has a reference to.
This difference between x := [value] and put(x, value) accounts for my confusion as to why I sometimes could, and sometimes couldn't, update the array. In short, I was doing it both ways at different times without fully comprehending the difference. There is no low-level clue to the different behavior in the syntax; one just has to have read the fine print. RTFM, I think they say.
In reading what I could find about the parameter problem in the 2nd Ed. of Ralph's book (yes, I know--I need to get the 3rd), I could find nothing in the vein of "If you want to update a structured parameter from within a procedure, here is how to do it: ..."
So, in the interest of filling the gap for newcomers and oldtimers alike who may be confused, here is how to do it and guarantee that the update will make it back to the caller:
# append a value to list_arg, which is passed in from the caller
procedure append_it(list_arg)
local new_list_value
new_list_value := # result of some computation
put(list_arg, new_list_value)
return
end
# change an element of list_arg:
procedure change_it(list_arg)
local changed_list_value, i
i := # e.g. a binary search for the proper element to modify
changed_list_value := # result of some computation
list_arg[i] := changed_list_value
return
end
And here is how NOT to do it:
# Grrr...
procedure how_dumb(list_arg)
local new_list
list_arg := [ # sequence of new values computed locally from list_arg
]
return
end
If anybody sees problems with these examples, be sure to chime in.